package com.sky.config;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * Redis 配置类
 *
 * @Author: Zhy
 * @Date: 2025-01-27 下午8:59
 * @Version: 1.0
 */
@Slf4j
@Configuration
public class RedisConfiguration {

	@Bean
	public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
		log.info("开始创建redis模板对象...");

		RedisTemplate redisTemplate = new RedisTemplate();
		// 设置 redis key、value 的序列化器
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		// value 值支持中文正常显示
		redisTemplate.setValueSerializer(new FastJsonRedisSerializer<Object>(Object.class));
		// 设置 redis 的连接工厂对象
		redisTemplate.setConnectionFactory(redisConnectionFactory);
		return redisTemplate;
	}

}
